 /* Copyright (C)
  * 2024 ZKLX Optoelectronic Technology Co.LTD
  * All rights reserved.
  */
 /**
  * @file cam_basler_ctrl.h
  * @brief basler相机控制头文件
  * @author xuke
  * @version 1.0
  * @date 2024-06-11
  */

#ifndef _CAM_BASLER_CTRL_H_
#define _CAM_BASLER_CTRL_H_

/*------------------Include Files----------------------------*/
#include <iostream>
#include "lx_serial.h"
/*------------------End of Include Files---------------------*/

/*------------------Macro Definition-------------------------*/
/*------------------End of Macro Definition------------------*/

/*------------------Typedefs Definition----------------------*/
class BaslerCamCtrl {
	public:
		enum TriggerSource {
			SOFTWARE = 0,
			LINE1 = 1,
			LINE2 = 2,
			LINE3 =3,
			LINE4 = 4,
			LINE5 =5 ,
			LINE6 = 6,
			LINE7 = 7,
			LINE8 =8 ,
			CC1=9,
			CC2=10,
			CC3=11,
			CC4=12,
			ShaftEncoder=13,
			FrequencyConverter =14,
		};

	private:
		std::string CAMERA_DEVICE = "/dev/ttyTHS1";
		//std::string CAMERA_DEVICE = "/dev/ttyS17";
		serial cameraSerial;
		//serial baseSerial;
		bool is_serial_opened;

		unsigned long MAX_EXPTIME = 10000000;
		unsigned long MIN_EXPTIME = 0;

		unsigned int MAX_AGAIN = 512;//gain * 33
		unsigned int MIN_AGAIN = 33;

	public:
		BaslerCamCtrl();
		~BaslerCamCtrl() = default;

		int CameraInitial(int speed);
		void CameraClose();

		uint32_t GetAddressValue(uint32_t address);
		int SetAddressValue(uint32_t address, uint32_t data);

		int SetExposureTime(unsigned int time);

		// 设置分辨率
		int SetImageWidth(unsigned int width);
		int SetImageHeight(unsigned int height);
		int GetImageWidth();
		int GetImageHeight();

		int SetCenterOffsetX(unsigned int x);
		int GetCenterOffsetX();
		int SetCenterOffsetY(unsigned int y);
		int GetCenterOffsetY();

		int SetCenterX(unsigned int x);
		int SetCenterY(unsigned int y);

		int SetAutoExposureUpperLimit(uint32_t value);
		int SetAutoExposureLowerLimit(uint32_t value);
		int SetAutoTargetValue(uint32_t value);
		int SetExposureMode(int mode);
		int GetExposureMode();

		int SetAnalogGain(unsigned int gain);

		int GetExposureTime();
		int GetMinExposureTime();
		int GetMaxExposureTime();

		int GetAnalogGain();
		int GetMaxAnalogGain();
		int GetMinAnalogGain();

		int SetDigitalGain(float gain);
		int GetDigitalGain(float& gain);

		int SetBaudRate(unsigned int rate);
		int GetBaudRate(unsigned int *rate);

		// 改变分辨率 (精电视 width == height)
		int SetSensorResolution(int size);
		int SetSensorWidthResolution(int width);
		int SetSensorHeightResolution(int height);

		void InitCameraSize();
		int SetCLTapGeometry(int taps);
		int GetCLTapGeometry();

		// 水平翻转
		int reverseX(bool reverse);
		bool get_reverseX();
		// 垂直翻转
		int reverseY(bool reverse);
		bool get_reverseY();

		// 保存用户set
		int saveUserSet();
		int selectUserSet(int set_num);

		// Trigger Source
		int triggerMode(bool mode);
		bool get_triggerMode();
		int triggerSourceAcquisition(TriggerSource triggerSource);
		int get_triggerSourceAcquisition();
		int set_AcquisitionFramePeriodEnable(bool is_enable);

		int set_pixelFormat(int val);
		int get_pixelFormat();
		int SetGainMode(int mode);
		int GetGainMode();
};
/*------------------End of Typedefs Definition---------------*/

/*------------------API Definition---------------------------*/
int shell_basler_camer_cmd(int argc, const char *argv[]);
/*------------------End of API Definition--------------------*/


#endif /* End of _CAM_BASLER_CTRL_H_ */

